package org.labuladong.前缀和技巧;

/**
 * @Auther: qingle
 * @Date: 2024/10/26-11:39
 * @Description:
 * @version: 1.0
 */
public class 前缀和2 {


	//nums = [2,3,1,1,4]
	public static void main(String[] args) {

		int[] nums = {2,3,1,1,4};
		int[] sum = accumulate(nums);
		for (int i : sum) {
			System.out.print(i+" ");
		}
	}

	private static int[] accumulate(int[] nums) {
		int sumAccumulate = 0;
		int[] sum = new int[nums.length];
		for (int i = 0; i < nums.length; i++) {
			sumAccumulate += nums[i];
			sum[i] = sumAccumulate;
		}
		return sum;
	}
}
